#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./esb/components/bk/apis/cc/del_set_host.py
# Compiled at: 2017-11-16 15:44:28
"""
Tencent is pleased to support the open source community by making 蓝鲸智云(BlueKing) available.
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
"""
from django import forms
from common.forms import BaseComponentForm, TypeCheckField
from common.constants import API_TYPE_OP
from components.component import Component
from .toolkit import tools, configs

class DelSetHost(Component):
    """
    apiLabel 清空集群下所有主机
    apiMethod POST
    
    ### 功能描述
    
    清空集群下所有主机
    
    ### 请求参数
    
    {{ common_args_desc }}
    
    #### 接口参数
    
    | 字段      |  类型      | 必选   |  描述      |
    |-----------|------------|--------|------------|
    | app_id    |  int       | 是     | 业务ID |
    | set_ids   |  array     | 是     | 集群ID |
    
    ### 请求参数示例
    
    ```python
    {
        "app_code": "esb_test",
        "app_secret": "xxx",
        "bk_token": "xxx",
        "app_id": 1,
        "set_ids": ["1"]
    }
    ```
    
    ### 返回结果示例
    
    ```python
    {
        "result": true,
        "code": "00",
        "message": "",
        "data": null
    }
    ```
    
    ### 返回结果参数说明
    
    | 字段      | 类型      | 描述      |
    |-----------|-----------|-----------|
    | result    | boolean   | 包含True和False，其中True表示成功，False表示失败 |
    | code      | string    | 返回错误码，其中"00"表示成功，其它表示失败 |
    | data      | object    | 返回数据，成功返回请求数据 |
    | messge    | string    | 返回错误消息 |
    """
    sys_name = configs.SYSTEM_NAME
    api_type = API_TYPE_OP
    host = configs.host

    class Form(BaseComponentForm):
        app_id = forms.CharField(label=u'业务ID', required=True)
        set_ids = TypeCheckField(label=u'集群ID', promise_type=list, required=True)

        def clean(self):
            data = self.cleaned_data
            return {'ApplicationID': data['app_id'],
               'SetID': (',').join(data['set_ids'])
               }

    def handle(self):
        client = tools.CCClient(self.outgoing.http_client)
        self.response.payload = client.post_request(self.host, '/api/set/delSetHost', data=self.form_data)
